<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
</head>

<body>
    <script>
        //创建佩奇一家
        //1.声明构造函数
        //首字母大写
        //要将参数写在形参里面
        // function Pig(a, b, c) {
        //     //peiqi.name = a
        //     this.name = a
        //     //peiqi.age = b
        //     this.age = b
        //     this.gender = c
        // }

        // //只能通过new关键词创建对象
        // //new实例化过程
        // const peiqi = new Pig('peiqi', '5', '雌')
        // const george = new Pig('george', '4', '雄')
        // const father = new Pig('father', '8', '雄')
        // const mother = new Pig('mother', '7', '雌')
        // const pig = new Pig

        // console.log(peiqi)
        // console.log(george)
        // console.log(father)
        // console.log(mother)
        // console.log(pig);

        //1.声明构造函数
        function Goods(name, price, count) {
            this.name = name
            this.price = price
            this.count = count
            this.sell = function () {
                console.log(`${this.name}被卖了${this.price * this.count}`);
            }
        }

        //2.实例化对象
        const xiaomi = new Goods('小米', '1999', '1')
        const huawei = new Goods('华为', '8999', '1')
        const iphone = new Goods('苹果', '28999', '110')

        // console.log(xiaomi);
        // console.log(huawei);
        // console.log(iphone);

        xiaomi.sell()
        huawei.sell()

    </script>
</body>

</html>